package cn.wen.java.lang;

/**
 * Title：类型辅助类
 * <p>
 * Description：
 * <p>
 * Copyright：Copyright (c) 2010-2012
 * 
 * @author <a href="mailto:ct_wen@qq.com">ctwen</a>, 温承瑭
 * @version Revision：1.0 Date：2011/4/13 Description：初完成。
 *          <p>
 */
public class HelperOfClass {

    /**
     * Assert that the provided object is an instance of the provided class.
     * 
     * <pre class="code">
     * HelperOfClass.isInstanceOf(Foo.class, foo);
     * </pre>
     * 
     * @param clazz the required class
     * @param obj the object to check
     * @see Class#isInstance
     */
    public static boolean isInstanceOf(Class<?> clazz, Object obj) {
	return obj != null && clazz.isInstance(obj);
    }

    /**
     * Assert that <code>superType.isAssignableFrom(subType)</code> is <code>true</code>.
     * 
     * <pre class="code">
     * HelperOfClass.isAssignableFrom(Number.class, myClass);
     * </pre>
     * 
     * @param superType the super type to check against
     * @param subType the sub type to check
     * @see Class#isAssignableFrom
     */
    public static boolean isAssignableFrom(Class<?> superType, Class<?> subType) {
	return subType != null && superType.isAssignableFrom(subType);
    }

}
